package com.hs.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.server.domain.VehZnshinfo;
import com.hs.server.exception.GlobalException;
import com.hs.server.mapper.VehZnshinfoMapper;
import com.hs.server.service.VehZnshinfoService;
import com.hs.server.utils.MD5Encryption;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author: chenjiarui
 * @Date: 2021-07-08 16:15
 */
@Service
public class VehZnshinfoServiceImpl extends ServiceImpl<VehZnshinfoMapper, VehZnshinfo> implements VehZnshinfoService {
    @Autowired
    VehZnshinfoMapper vehZnshinfoMapper;

    @Override
    public synchronized void AddVehZnshinfo(VehZnshinfo vehZnshinfo) {
        vehZnshinfoMapper.insert(vehZnshinfo);
    }

    @Override
    public VehZnshinfo GetVehZnshinfoByLsh(String lsh) {
        if(StringUtils.isBlank(lsh)) {
            throw new GlobalException("获取车辆信息失败");
        }
        return vehZnshinfoMapper.selectById(lsh);
    }

    @Override
    public void updateVehZnshinfo(VehZnshinfo vehZnshinfo) {
        vehZnshinfo.setJyw(MD5Encryption.encryption(vehZnshinfo.toString())); //更新校验位
        if(vehZnshinfoMapper.updateById(vehZnshinfo) != 1) {
            throw new GlobalException("更改车辆信息失败");
        }
    }
}
